import { defineStore } from "pinia";

export const useSubjectStore = defineStore({
  id: "subject",
  state: () => {
    return {
      // subjectTreeData: [], //章节树
      // 章节目录
      chapterList: [],
      // 课程详情
      courseDetail: {},
    };
  },
  getters: {},
  actions: {
    // 获取课程目录
    addChapterList(list) {
      this.chapterList = list;
    },
    addCourseDetail(data) {
      // 遍历data 给data添加序号
      this.chapterList = [];
      data.children?.forEach((item, index) => {
        item.index = index + 1;
        if (item?.children) {
          this.chapterList = [...this.chapterList, ...item.children];
        }
      });
      this.courseDetail = data;
    },
  },
});
